<template>
	<view class="page">


		<view class="u-padding-20 u-font-weight">申请代理</view>

		<u-form :model="form" ref="uForm" label-width="150">
			<view class="" style="background: #fff;padding:  0 20rpx;">
				<u-form-item label="申请代理">
					<u-radio-group v-model="form.type">
						<u-radio v-for="(item, index) in radioList" :key="index" :name="item.value">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
			</view>
			<view class="u-padding-20 u-font-weight">基本资料</view>
			<view class="" style="background: #fff;padding:  0 20rpx;">
				<u-form-item label="姓名" prop="username">
					<u-input v-model="form.username" />
				</u-form-item>
				<u-form-item label="性别" >
					<u-radio-group v-model="form.sex">
						<u-radio v-for="(item, index) in sexList" :key="index" :name="item.value">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="年龄" prop="age">
					<u-input v-model="form.age" />
				</u-form-item>
				<u-form-item label="住址" prop="address">
					<u-input v-model="form.address" />
				</u-form-item>
			</view>
		</u-form>



		<view class="bottomFix">
			<u-button type="success" @click="sumbit">立即申请</u-button>
		</view>

		<u-toast ref="uToast" />
	</view>

</template>

<script>
	export default {
		data() {
			return {
				radioList: [{
						name: '城市代理',
						value: 0
					},
					{
						name: '酒店代理',
						value: 1
					}
				],

				sexList: [{
					name: '男',
					value: 1
				}, {
					name: '女',
					value: 2
				}],

				form: {
					username: '',
					age: '',
					address: '',
					type: 0,
					sex: 1
				},
				rules: {
					username: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur'],
					}],
					age: [{
required: true,
						message: '请输入年龄',
						trigger: ['change', 'blur'],
					}],
					address: [{
required: true,
						message: '请输入地址',
						trigger: ['change', 'blur'],
					}],
				}
			};
		},

		methods: {
			sumbit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$u.post('/user/applyAgent',
							this.form).then(res => {
							this.$refs.uToast.show({
								title: '提交成功',
								type: 'success',
								back: true
							})
						}).catch(err => {})
					} else {
						console.log('验证失败');
					}
				});
			}
		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
	};
</script>


<style>
	.page {
		background: #F1F1F1;
		min-height: 100vh;
		display: inline-block;
		width: 750rpx;
	}
</style>
